package com.wangzhixuan.commons;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Indexed;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 * 系统常量
 *
 * @author lixin
 */
@Component
public class Constant {
    @Autowired
    private Environment environment;
    @Autowired
    private ObjectMapper objectMapper;
    public static Environment env;
    public static ObjectMapper staticObjectMapper;
    private static boolean IS_LOCAL;
    public static final String CONFIG_GROUP = "spring-shiro-traning";
    public static String ACTIVE_ENV;
    public static String APPLICATION_NAME;
    /**
     * 上传文件地址
     */
    public static String UPLOAD_PATH;
    /**
     * 访问文件根路径
     */
    public static String VISIT_PATH;

    @PostConstruct
    public void init() {
        env = environment;
        staticObjectMapper=objectMapper;
        APPLICATION_NAME = environment.getProperty("spring.application.name", "springboot-project");
        ACTIVE_ENV = environment.getProperty("spring.profiles.active", "local");
        IS_LOCAL = StringUtils.equalsIgnoreCase(ACTIVE_ENV, "local");
        UPLOAD_PATH = environment.getProperty("files.path", "D:\\www\\static\\uploadFiles");
        VISIT_PATH = environment.getProperty("files.visit", "/upload");
    }

    public static boolean isLocal() {
        return IS_LOCAL;
    }

    public String getVisitPath() {
        return VISIT_PATH;
    }
}
